//
//  ToastIOS.m
//  qipay
//
//  Created by wyht－ios－dev on 2018/7/3.
//  Copyright © 2018年 Facebook. All rights reserved.
//

#import "ToastIOS.h"
#import "UIView+Toast.h"
#import "VipCUstomerManager.h"

@implementation ToastIOS

+ (void)toast:(NSString *)msg {
    dispatch_async(dispatch_get_main_queue(), ^{
      UIViewController *vc = [[VipCustomerManager getInstance] getViewController];
      //        UIViewController *vc=[self.class getCurrentVC];
      if (vc) {
        [CSToastManager setDefaultPosition:CSToastPositionCenter];
        [vc.view makeToast:msg];
      }
    });
}

//获取当前viewController
+(UIViewController *) getCurrentVC {
  UIViewController *result = nil;
  
  UIWindow * window = [[UIApplication sharedApplication] keyWindow];
  if (window.windowLevel != UIWindowLevelNormal) {
    NSArray *windows = [[UIApplication sharedApplication] windows];
    for(UIWindow * tmpWin in windows) {
      if (tmpWin.windowLevel == UIWindowLevelNormal) {
        window = tmpWin;
        break;
      }
    }
  }
  
  UIView *frontView = [[window subviews] objectAtIndex:0];
  id nextResponder = [frontView nextResponder];
  
  if ([nextResponder isKindOfClass:[UIViewController class]]) {
    result = nextResponder;
  } else {
    result = window.rootViewController;
  }
  
  return result;
}

@end
